import HttpUtils from "./HttpUtils";
import {EventBean} from "./event/EventBean";

export const EVENT_JOIN = "JOIN";
export const EVENT_JOIN_OK = "JOIN_OK";
export const EVENT_JOIN_FAIL = "JOIN_FAIL";
export const EVENT_FIRST_FPS_ELAPSED = "FIRST_FPS_ELAPSED";
export const EVENT_QOE = "QOE";

export default class AnalysisUtils {

    static eventBean = new EventBean();

    static putEvent({eventName, duration, bean}) {
        if (bean == null) {
            bean = this.copyBean(eventName);
        }

        this.setCommonField(bean, eventName)

        if (duration) {
            bean.duration = duration;
        }

        HttpUtils.post(bean);
    }

    static copyBean(eventName) {
        let bean = JSON.parse(JSON.stringify(this.eventBean));
        this.setCommonField(bean, eventName);
        return bean;
    }

    static setCommonField(bean, eventName) {
        bean.event = eventName;
        bean.localTs = new Date().getTime();
    }
}
